<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>后台主界面</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/admin.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/daily_record.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/treeview.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/news_list.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/news_add.css' type="text/css" />
<script src="<?php echo $static_url; ?>common/js/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="<?php echo $static_url; ?>common/js/common.js" type="text/javascript"></script>
<script src="<?php echo $static_url; ?>common/js/jquery.treeview.js" type="text/javascript"></script>
</head>
<body class="body_background">
	<div>
		<?php echo $header_nav; ?>
		<div class="common_container clearfix">
			<div class="crumbs">
				<span class="catalogue">文章管理</span>
				<a href="/www/admin/news/news_lists.php">文章列表</a> |
				<a href="/www/admin/news/news_add.php?category_id=<?php echo $category_id; ?>">添加文章</a> |
				<a href="/www/admin/news/empty_add.php?category_id=<?php echo $category_id; ?>">添加空白文章</a> |
				<a href="/www/admin/news/news_relative.php">手动推荐</a> |
				<a href="/www/admin/news/news_recover.php">回收站</a>
			</div>
			<div class="treeview_container" id="side_container">
				<div class="closeSidebar"><i title="点击隐藏左菜单" class="icon_close"></i></div>
				<h4>文章栏目</h4>
				<ul id="browser" class="filetree"></ul>
			</div>
			<div class="sidebar_container_hidden" style="margin-top:10px;margin-right:5px;"  >
				<div class="openSidebar"><i title="点击显示左菜单" class="icon_open"></i></div>
			</div>
			<div class="daily_record_main" id="main_container">
				<div class="news_main_container">
					<table class="record_tips"><tr><td class="colorstyle"><?php echo $category_name; ?></td></tr></table>
					<form id="new_form" action="/www/admin/news/do/do_order.php?category_id=<?php echo $category_id; ?>" method="post">
					<table class="news_table">
						<thead>
							<tr>
								<th><input id="check_box" type="checkbox" onclick="selectall('ids[]');"></th>
								<th>排序</th>
								<th>ID</th>
								<th>标题</th>
								<th>点击量</th>
								<th>发布人</th>
								<th>发布时间</th>
								<th>管理</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach($news_rs as $row): ?>
							<tr>
								<td><input type="checkbox" value="<?php echo $row['title_id']; ?>" name="ids[]"></td>
								<td>
									<input type="text" name="orders[]" value="<?php echo $row['orders']; ?>" style="width:40px;text-align:center;border:0;">
								</td>
								<td>
									<?php
									if( strlen($row['empty_id'])>3 ){
										echo '<span style="color:red;">'.$row['empty_id'].'</span>';
									}else{
										echo $row['title_id'];
									}
									?>
									<input type="hidden" name="title_id[]" value="<?php echo $row['title_id']; ?>" >
								</td>
								<td style="text-align:left">
									<a href="<?php echo $row['static_url']; ?>" target="_blank">
										<?php echo $row['title']; ?>
									</a>
								</td>
								<td><?php echo $row['click']; ?></td>
								<td><?php echo $row['create_username']; ?></td>
								<td id="publish_time_<?php echo $row['title_id']; ?>">
									<?php 
									if( $row['is_publish'] == 1 && $row['publish_time'] > time() )
									{
										echo '<span style="color:red;font-weight:bold;">'.date('Y-m-d H:i:s',$row['publish_time']).'</span>';
									}
									elseif( $row['is_publish'] == 2 && $row['publish_time'] != 0 )
									{
										echo date('Y-m-d H:i:s',$row['publish_time']);
									}
									else
									{
										echo date('Y-m-d H:i:s',$row['created']);
									}
									?>
								</td>
								<td>
									<a href="<?php echo $row['static_url']; ?>" target="_blank">预览</a> | 
									<a href="javascript:;" onclick="set_top('<?php echo $row['title_id']; ?>');" id="index_top_<?php echo $row['title_id']; ?>">
										<?php if($row['index_top']==1){echo '置顶';}else{echo '已置顶';}; ?>
									</a> | 
									<?php if($row['is_publish']==1 && $row['publish_time']>time()){ ?>
										<span id="index_publish_now_<?php echo $row['title_id']; ?>">
											<a href="javascript:;" onclick="publish_now('<?php echo $row['title_id']; ?>');" >立刻发布</a>
										</span> | 
									<?php }else{echo '已发布 | ';} ?>
									<?php if( strlen($row['empty_id'])>3 ){ ?>
									<a href="/www/admin/news/empty_edit.php?title_id=<?php echo $row['title_id']; ?>&empty_id=<?php echo $row['empty_id']; ?>">修改</a> |
									<?php }else{ ?>
									<a href="/www/admin/news/news_edit.php?title_id=<?php echo $row['title_id']; ?>&this_history_id=<?php echo $row['title_history_id']?>">修改</a> |
									<?php } ?>
									<a id="del-<?php echo $row['title_id']; ?>" href="javascript:del('<?php echo $row['title_id']; ?>');" onclick="return confirm('确定要删除《<?php echo $row['title_id'].' '.$row['title'];?>》这篇文章吗？')" >删除</a>
								</td>
							</tr>
							<?php endforeach; ?>
						</tbody>
						<tfoot>
							<tr>
								<td colspan="8" style="text-align:left">
									&nbsp;&nbsp;&nbsp;<label for="check_box">全选/取消</label>&nbsp;&nbsp;&nbsp;
									<a class="btn" href="javascript:;" onclick="{if(confirm('确定删除所选文章？')){delAll();}return false;}">删除</a>&nbsp;&nbsp;&nbsp;
									<a href="javascript:;" onclick="document.getElementById('new_form').submit();">排序</a>
								</td>
							</tr>
							<?php if( $category_id > 0 ): ?>
							<tr>
								<td colspan="8" style="text-align:left">
									&nbsp;&nbsp;&nbsp;<div style="display:inline;" id="category"></div>&nbsp;
									<a class="btn" href="javascript:;" onclick="move_news();">移动</a>
								</td>
							</tr>
							<?php endif; ?>
							<?php if( $page_html != '' ): ?>
							<tr>
								<td class="navPage" colspan="8">&nbsp;&nbsp;<?php echo $page_html; ?></td>
							</tr>
							<?php endif; ?>
						</tfoot>
					</table>
					</form>
						<div id="my_div"></div>
				</div>
			</div>
		</div>
	</div>

<script>
//加载栏目数据，并实例化
$(function(){
	var browser = $('#browser');
	browser.html('');
	$.ajax({
		type: "POST",
		url: "/admin/news/ajax/ajax_news_left_baner.php",
		dataType: 'html',
		data: {},
		beforeSend: function(){
			browser.html( '加载中...' );
		},
		success: function(data){
			browser.html( data ).treeview();
		}
	});
});

//获取栏目
function category_start(i){<!-- i:id号 -->
	$.ajax({
		type: "POST",
		url: "/admin/news/category/ajax/ajax_start.php",
		dataType:'html',
		data: {"id":i,"news":2},
		success: function(data){
			$("#category").html("");
			html = data+'<input type="hidden" name="parent_id" id="parent_id" value="'+i+'"/>';
			$("#category").html(html);
		}
	});
}

//栏目切换
$("select[id^='category_']").live("change", function(){
	var i = $(this).val();
	$.ajax({
		type: "POST",
		url: "/admin/news/category/ajax/ajax_get.php",
		dataType:'html',
		data: {"id":i,"news":2},
		success: function(data){
			$("#category").html("");
			$("#category").html(data);
		}
	});
});

//初始化栏目
category_start(<?php echo $category_id;?>);

//删除
function del(i){<!-- i:id号 -->
	$.ajax({
		type: "POST",
		url: "/admin/news/ajax/ajax_del.php",
		dataType:'json',
		data: {"id":i},
		beforeSend: function(){
			$('#del-'+i).html( '正在删除' );
		},
		success: function(msg){
			alert(msg.string);
			$('#del-'+i).html( '删除' );
			if(msg.error){
				window.location.href="/www/admin/news/news_lists.php?category_id=<?php echo $category_id; ?>&page=<?php echo $page; ?>";
			}
		}
	});
}
	
//设置置顶
function set_top(i){
	$.ajax({
		type: "POST",
		url: "/admin/news/ajax/ajax_top.php",
		dataType:'json',
		data: {"title_id":i},
		success: function(msg){
			if(msg.error===true){
				$("#index_top_"+i).html(msg.string);
			}else{
				alert(msg.string);
			}
		}
	});
}

//立刻发布
function publish_now(i){
	$.ajax({
		type: "POST",
		url: "/admin/news/ajax/ajax_publish_now.php",
		dataType:'json',
		data: {"title_id":i},
		success: function(msg){
			if(msg.error===true){
				$("#index_publish_now_"+i).html('');
				$("#index_publish_now_"+i).html('已发布');
				$("#publish_time_"+i).html('');
				$("#publish_time_"+i).html(msg.string);
			}else{
				alert(msg.string);
			}
		}
	});
}

//全选
function selectall(name) {
	if ($("#check_box").attr("checked")=='checked') {
		$("input[name='"+name+"']").each(function() {
		$(this).attr("checked","checked");
		});
	} else {
		$("input[name='"+name+"']").each(function() {
		$(this).removeAttr("checked");
		});
	}
}

//批量删除
function delAll(){
	var checks = '';
	$("input[name='ids[]'][type=checkbox]:checked").each(function() {
		checks += $(this).val() + "|";//动态拼取选中的checkbox的值，用“|”符号分隔
	});
	$.ajax({
		type: "POST",
		url: "/admin/news/ajax/ajax_delAll.php",
		dataType: 'json',
		data: {"title_id":checks},
		success: function(msg){
			alert(msg.string);
			if(msg.error){
				window.top.location.reload();
			}
		}
	});
}

//批量移动
function move_news(){
	var checks = '';
	$("input[name='ids[]'][type=checkbox]:checked").each(function() {
		checks += $(this).val() + "|";//动态拼取选中的checkbox的值，用“|”符号分隔
	});
	var parent_id = $("#parent_id").val();
	if(checks == '' || parent_id == 0 || parent_id == <?php echo $category_id; ?>){
		alert('请先选择文章并变动栏目！');
	}else{
		$.ajax({
			type: "POST",
			url: "/admin/news/ajax/ajax_move_news.php",
			dataType:'json',
			data: {"title_id":checks,"old_category_id":<?php echo $category_id; ?>,"new_category_id":parent_id},
			success: function(msg){
				alert(msg.string);
				if(msg.error){
					window.top.location.reload();
				}
			}
		});
	}
}
</script>
</body>
</html>